package cc.wsyw126.java.nowcoder;

/**
 * Created by dp on 17/3/25.
 */
public class FindNumberInArray {
    public boolean Find(int target, int[][] array) {
        if (array == null) return false;
        int row = array.length - 1;
        int column = array[0].length - 1;
        boolean result = doFind(target, array, 0, 0, row, column);
        return result;
    }

    private boolean doFind(int target, int[][] array, int i, int j, int row, int column) {
        if (i > row || j > column) {
            return false;
        }
        if (array[i][column] == target) {
            return true;
        } else if (array[i][column] <target) {
            i++;
        } else if (array[i][column] > target) {
            column--;
        } else {
            return false;
        }
        return doFind(target, array, i, j, row, column);
    }

    public static void main(String[] args) {
        FindNumberInArray findNumberInArray = new FindNumberInArray();
        int[][] array = {{1,2,3}, {3,4,5}};
        boolean find = findNumberInArray.Find(0, array);
        System.out.println("find = " + find);
    }
}
